/*    This file is part of nit.
 *
 *    Nit is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Nit is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with nit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ACTS_H
#define ACTS_H

#include "map.h"

#define ACT_FAIL() return act_failure

typedef Map Acts;

typedef void *(*Act_do)(int real, void *dat, void *args, void *extra);
typedef void *(*Act_undo)(void *cng, void *dat, void *args, void *extra);
typedef void *(*Act_dif)(void *cng, void *dat, void *args, void *extra);

typedef struct Action {
	Act_do do_it;
	Act_undo undo;
	Act_dif dif;
} Action;

typedef enum Act_type {
	ACT_DO,
        ACT_UNDO,
        ACT_REDO,
        ACT_DIF,
	ACT_REDIF
} Act_type;

typedef struct Act {
        Act_type type;
	int real;
	uint32_t key_len;
	void *key;
	void *dat;
	void *args;
	void *cng;
} Act;

extern char act_failure[];

Nit_error
acts_init(Acts *acts);

#define acts_dispose(...) map_dispose(__VA_ARGS__)

Nit_error
acts_add(Acts *acts, uint32_t key_len, const void *key,
	 Act_do do_it, Act_undo undo, Act_dif dif);

Nit_error
acts_act(Acts *acts, Act *act, void *extra);

#endif
